package com.ljt.yupictureddd.domain.space.valueobject;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum SpaceRoleEnums {

    VIEWER("浏览者", "viewer"),

    EDITOR("编辑者", "editor"),

    ADMIN("管理员", "admin");


    private final String text;

    private final String value;

    SpaceRoleEnums(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取枚举
     *
     * @param value
     * @return
     */
    public static SpaceRoleEnums getEnumByValue(String value) {
        if (ObjUtil.isEmpty(value)) {
            return null;
        }
        SpaceRoleEnums userRoleEnums = Arrays.stream(SpaceRoleEnums.values())
                .filter(space -> space.getValue().equals(value))
                .findFirst()
                .get();
        return userRoleEnums;
    }
}
